#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    bool isPrefixString(string s, vector<string>& words) {
        int pos = 0;
        string same(words[pos++]);
        int i = 0;
        while (i < s.size())
        {
            if (i == same.size())
            {
                if (pos == words.size())
                    return false;
                same += words[pos++];
            }
            if (s[i] != same[i])
            {
                return false;
            }

            ++i;
        }

        return i == same.size();
    }
};